<?php
    include('session.inc');
    require_once('funct.inc');
    include 'color_style.php';
    include '../definitions.inc.php';
    include LANGUAGE;
    if(!GetAdminID($ID)){echo LOGIN_ERR;exit;}
    if(!Right_Check(3)){header('Location:error.php');exit;}
    
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <?php echo '<meta http-equiv="Content-Type" content="text/html; charset='._CHARSET_.';">'; ?>

    <?php include 'html_style.php';?>


</head>
<?php

print "<body bgcolor=".Background_Color.">";

require_once('OpenDB.inc');
require_once('functs.inc');
do
{
    if (!OpenDB()){echo OPEN_DB_ERR; break;}

   if($_REQUEST["PageQuanter"]=="")
       $PageNo=$_REQUEST["PageNo"];
    else
       $PageNo=$_REQUEST["PageNo"]-1;

    if($PageNo=="" || $PageNo==-1) $PageNo=0;
 //Definicie tovarov=================================
    $ItemsOnPage = ITEMSONPAGE;
    $ShowQvantumPage = SHOWQVANTUMPAGE;
 //===================================================
    $ActualQvantumPage=$_REQUEST["ActualQvantumPage"];
    if($ActualQvantumPage=="")$ActualQvantumPage = 0;

    $Logged_Admin   =$_SESSION['admin'];
    $index=0;
    $roll_show="/";

    $events=$_REQUEST["events"];
    switch($events) {
           case 'delete_chat':      //SQL_Delete_Chat($_REQUEST["Ch_ID"]); break;
                                                                   //print $_REQUEST["GrantDelete"]."*".;
                                                                     if ($_REQUEST["GrantDelete"]!="YES")
                                                                             print"
                                                                                     <center>
                                                                                             <table border=\"1\" bgcolor=".BACKGROUND_IN_TABLE.">
                                                                                                     <tr>
                                                                                                             <td>
                                                                                                                     ".CH_VYMAZANIE."
                                                                                                                     <center><form action=\"chat_management.php\" target=\"place\" method=\"post\">
                                                                                                            <input type=\"hidden\" value=\"".$ActualQvantumPage."\" name=\"ActualQvantumPage\" />
                                                                                                            <input type=\"hidden\" name=\"events\" value=\"delete_chat\" />
                                                                                                            <input type=\"hidden\" name=\"Ch_ID\" value=\"".$_REQUEST["Ch_ID"]."\" />
                                                                                                            <input type=\"hidden\" name=\"PageNo\" value=\"".$PageNo."\" />
                                                                                                            <input type=\"hidden\" name=\"GrantDelete\" value=\"YES\" />
                                                                                                            <input type=\"hidden\" value=\"".$F_Surname."\" name=\"F_Surname\" />
                                                                                                            <input type=\"hidden\" value=\"".$F_Organisation."\" name=\"F_Organisation\" />
                                                                                                            <input type=\"hidden\" value=\"".$F_ICO."\" name=\"F_ICO\" />
                                                                                                            <input type=\"submit\" value=\"".CH_ANO."\" style=\"width :100px; background-color: ".BUTTON_ON_OUT.";\"
                            onmouseover=\"this.style.backgroundColor='".BTN_IN_TABLE."'; this.style.fontWeight='bold';\";
                            onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
                                                                                                            </form> </center><center>
                                                                                                            <form action=\"chat_management.php\" target=\"place\" method=\"post\">
                                                                                                            <input type=\"hidden\" value=\"".$ActualQvantumPage."\" name=\"ActualQvantumPage\" />
                                                                                                            <input type=\"hidden\" name=\"events\" value=\"show_order\" />
                                                                                                            <input type=\"hidden\" name=\"Ch_ID\" value=\"".$_REQUEST["Ch_ID"]."\" />
                                                                                                            <input type=\"hidden\" name=\"PageNo\" value=\"".$PageNo."\" />
                                                                                                            <input type=\"hidden\" value=\"".$F_Surname."\" name=\"F_Surname\" />
                                                                                                            <input type=\"hidden\" value=\"".$F_Organisation."\" name=\"F_Organisation\" />
                                                                                                            <input type=\"hidden\" value=\"".$F_ICO."\" name=\"F_ICO\" />
                                                                                                            <input type=\"submit\" value=\"".CH_NIE."\" style=\"width :100px; background-color: ".BUTTON_ON_OUT.";\"
                            onmouseover=\"this.style.backgroundColor='".BTN_IN_TABLE."'; this.style.fontWeight='bold';\";
                            onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />
                                                                                                            </form> </center>
                                                                                                             </td>
                                                                                                     </tr>
                                                                                             </table>
                                                                                     </center>
                                                                                        ";
                                                                                else
                                                                                     SQL_Delete_Chat($_REQUEST["Ch_ID"]);
                                                                                break;
           case 'show_chat':        $roll_show = rutine_menu($_REQUEST["roll_show"],$_REQUEST["Ch_ID"]);
                                    $roll_edit=$_REQUEST["roll_edit"];
                                    break;
           default:break;
    }

    print("<center><b>".CH_TITULOK."</b></center>");

    //**************************************************************************
    //
    //Vytvorenie menu pre vyber zobrazovanej stranky (rozdelenie zobrazovane hotovaru) - ulozene hore
    //
    //**************************************************************************
    $sql_psel= "SELECT COUNT(*) FROM chat";
    $sql_array_adm = mysql_fetch_row(mysql_query($sql_psel));
    if($sql_array_adm[0]/$ItemsOnPage==($PageNo)) $PageNo--;
    if($sql_array_adm[0]/$ItemsOnPage<=$ActualQvantumPage) $ActualQvantumPage=$ActualQvantumPage-$ShowQvantumPage;
    do{
     if (($sql_array_adm[0]/$ItemsOnPage)<=1) break;
     print"<CENTER><table style=\"position:relative;  top:5px;\"><tr>";

// Podmienka prvej >>>> --------------------------------------------------------------------
      if(($sql_array_adm[0]/$ItemsOnPage>$ShowQvantumPage) and ($ActualQvantumPage-$ShowQvantumPage>=0)){
             print "<td>";
             print "<form  action=\"chat_management.php\" target=\"place\" method=\"post\">";
             if($sql_array_adm[0]>$ShowQvantumPage)
               print "<input type=\"submit\" value=\"<<<\"  style=\"width :50px; background-color: ".BUTTON_ON_OUT.";\"
                             onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                             onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />";
               $xxx=$ActualQvantumPage-$ShowQvantumPage;
               $Pagexxx=$xxx;
               print "<input type=\"hidden\" value=\"".$Pagexxx."\" name=\"PageNo\" />";
               print "<input type=\"hidden\" value=\"".$xxx."\" name=\"ActualQvantumPage\" />";
               print "<input type=\"hidden\" value=\"".$Path."\" name=\"path\" />";
               print "<input type=\"hidden\" value=\"".$Category_ID."\" name=\"ID\" />";
             print "</form>";
             print "</td>";
             }
 //--------------------------------------------------------------------------------------

//podmienka zvysnych stranok------------------------------------------------------------
          if(($ActualQvantumPage/$ShowQvantumPage)==floor(($sql_array_adm[0]/$ItemsOnPage)/$ShowQvantumPage))
              { if($sql_array_adm[0]%$ItemsOnPage==0)
                    $ShowActualQvantumPage=((($sql_array_adm[0]/$ItemsOnPage)%$ShowQvantumPage));
                else
                    $ShowActualQvantumPage=((($sql_array_adm[0]/$ItemsOnPage)%$ShowQvantumPage)+1);
              }
          else
              {$ShowActualQvantumPage=$ShowQvantumPage;}
 //---------------------------------------------------------------------------------------
      for($i=$ActualQvantumPage;$i<$ActualQvantumPage+$ShowActualQvantumPage;$i++)
    {
      print "<form  action=\"chat_management.php\" target=\"place\" method=\"post\">";
          print "<td>";
          $Xi=$i+1;
          if($PageNo==$i)
            print "<input type=\"submit\" value=\"".$Xi."\" name=\"PageNo\"  style=\"width :50px; background-color: ".BUTTON_ON_OVER.";\" />";
          else
            print "<input type=\"submit\" value=\"".$Xi."\" name=\"PageNo\" style=\"width :25px; background-color: ".BUTTON_ON_OUT.";\"
                            onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                            onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\"
                        />";
          print "<input type=\"hidden\" value=\"1\" name=\"PageQuanter\" />";
          print "<input type=\"hidden\" value=\"".$ActualQvantumPage."\" name=\"ActualQvantumPage\" />";
          print "<input type=\"hidden\" value=\"".$Path."\" name=\"path\" />";
          print "<input type=\"hidden\" value=\"".$Category_ID."\" name=\"ID\" />";
          print "</form>";
          print "</td>";
    }

 //podmienka doprednej >>>> -----------------------------------------------------------
if(($sql_array_adm[0]/$ItemsOnPage) > ($ActualQvantumPage+$ShowQvantumPage)){
      print "<td>";
      print "<form  action=\"chat_management.php\" target=\"place\" method=\"post\">";
      print "<input type=\"submit\" value=\">>>\"  style=\"width :50px; background-color: ".BUTTON_ON_OUT.";\"
              onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
              onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />";
      $xxx=$ActualQvantumPage+$ShowQvantumPage;
      $Pagexxx=$xxx;
      print "<input type=\"hidden\" value=\"".$Pagexxx."\" name=\"PageNo\" />";
      print "<input type=\"hidden\" value=\"".$xxx."\" name=\"ActualQvantumPage\" />";
      print "<input type=\"hidden\" value=\"".$Path."\" name=\"path\" />";
      print "<input type=\"hidden\" value=\"".$Category_ID."\" name=\"ID\" />";
    print "</form>";
    print "</td>";
    }
 //--------------------------------------------------------------------------------------
    print "</tr></table></center>";
    PrintLine();
    }while(false);

    print "<br />";
    //**************************************************************************
    //
    //Naplneneie obsahu stranky datami z databazy
    //
    //**************************************************************************
    if ($PageNo<0) $PageNo=0;
    
    
        $From   = $PageNo*$ItemsOnPage;
        $sql_psel=  "SELECT * FROM chat ORDER BY ID DESC LIMIT ".$From.",".$ItemsOnPage;
        $Product_source = mysql_query($sql_psel);
        $counter=0;
        while($sql_array_adm = mysql_fetch_object($Product_source))
        {
            $ShowAsDetails = is_roll($roll_show,$sql_array_adm->ID);
            if(!$ShowAsDetails)
            {
                    if(($counter%2))
                        print "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"98%\" bgcolor=\"".TR_BACKGOUND_COLOR_2."\">";
                    else
                        print "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"98%\" bgcolor=\"".TR_BACKGOUND_COLOR_1."\">";

                    //zobrazenie nazvu tovaru
                    print "<tr><td>";
                        if(($counter%2))
                            print "<table  border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" bgcolor=\"".TR_BACKGOUND_COLOR_2."\"><tr>";
                        else
                            print "<table  border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" bgcolor=\"".TR_BACKGOUND_COLOR_1."\"><tr>";

                    print "<td align=\"left\">";
                      print("<font color=\"black\">".date(sttngs_DATE_FORMAT.', '.sttngs_TIME_FORMAT,strtotime($sql_array_adm->Ch_DateTime))." <b>".$sql_array_adm->Ch_Name." ".$sql_array_adm->Ch_Surname."</b></font color>");
                    print "</td>";
                    print "<td align=\"right\">";
                      print("<b><font color=".TEXT_COLOR.">(".$sql_array_adm->Ch_Title.")</font color></b>");
                    print "</td>";
                    print "</tr></table></td>";

                    print "<td align=\"right\" width=\"83px\">";
                          print "<form action=\"chat_management.php\" target=\"place\" method=\"post\">";
                            print "<input type=\"hidden\" value=\"".$ActualQvantumPage."\" name=\"ActualQvantumPage\">";
                            print "<input type=\"hidden\" name=\"events\" value=\"show_chat\">";
                            print "<input type=\"hidden\" name=\"roll_show\" value=\"".$roll_show."\">";
                            print "<input type=\"hidden\" name=\"Ch_ID\" value=\"".$sql_array_adm->ID."\">";
                            print "<input type=\"hidden\" name=\"PageNo\" value=\"".$PageNo."\">";
                            print "<input type=\"submit\" value=\"".CH_ZOBRAZIT."\" style=\"width :80px; background-color: ".BUTTON_ON_OUT.";\"
                            onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                            onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\">";
                          print "</form>";
                          print "</td>";

                        print "<td align=\"right\" width=\"63px\">";
                          print "<form action=\"chat_management.php\" target=\"place\" method=\"post\">";
                            print "<input type=\"hidden\" value=\"".$ActualQvantumPage."\" NAME=\"ActualQvantumPage\">";
                            print "<input type=\"hidden\" name=\"events\" value=\"delete_chat\">";
                            print "<input type=\"hidden\" name=\"roll_show\" value=\"".$roll_show."\">";
                            print "<input type=\"hidden\" name=\"Ch_ID\" value=\"".$sql_array_adm->ID."\">";
                            print "<input type=\"hidden\" name=\"PageNo\" value=\"".$PageNo."\">";
                            print "<input type=\"submit\" value=\"".CH_VYMAZ."\" style=\"width :60px; background-color: ".BUTTON_ON_OUT.";\"
                            onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                            onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\">";
                          print "</form>";
                          print "</td></tr>";

            }
            else
            {
                if($ShowAsDetails){
                    if(($counter%2))
                        print "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"98%\" bgcolor=\"".TR_BACKGOUND_COLOR_2."\">";
                    else
                        print "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"98%\" bgcolor=\"".TR_BACKGOUND_COLOR_1."\">";

                    print "<tr><td>";


                    //***********zobrazenie mena, priezviska, nick, prav********
                    if(($counter%2))
                        print "<table  border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"".TR_BACKGOUND_COLOR_2."\">";
                    else
                        print "<table  border=\"0\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"".TR_BACKGOUND_COLOR_1."\">";

                                        print"
                                                <tr>
                                                        <td colspan=\"2\">
                                                              ".date(sttngs_DATE_FORMAT.', '.sttngs_TIME_FORMAT,strtotime($sql_array_adm->Ch_DateTime))."
                                                              <br />
                                                              <br />
                                                        </td>
                                                </tr>
                                                <tr>
                                                        <td>
                                                                ".CH_MENO.":
                                                        </td>
                                                        <td>
                                                                <b>".$sql_array_adm->Ch_Name."</b>
                                                        </td>
                                                </tr>
                                                <tr>
                                                        <td>
                                                                ".CH_PRIEZVISKO.":
                                                        </td>
                                                        <td>
                                                                <b>".$sql_array_adm->Ch_Surname."</b>
                                                        </td>
                                                </tr>
                                                <tr>
                                                        <td>
                                                                ".CH_MAIL.":
                                                        </td>
                                                        <td>
                                                                <A HREF=\"mailto:".$sql_array_adm->Ch_Email."\">".$sql_array_adm->Ch_Email."</A>
                                                        </td>
                                                </tr>
                                                <tr height=\"40px\">
                                                        <td>
                                                                ".CH_PREDMENT.":
                                                        </td>
                                                        <td>
                                                                <b>".$sql_array_adm->Ch_Title."</b>
                                                        </td>
                                                </tr>
                                                <tr>
                                                        <td>
                                                                ".CH_TEXT.":
                                                        </td>
                                                        <td>
                                                               <textarea wrap=\"ON\" name=\"Ch_Text\" readonly=\"readonly\" style=\"height:100px;width:500px;\">".$sql_array_adm->Ch_Text."</textarea>
                                                       </td>
                                                </tr>";//koniec print

                    print "</table>";
                    //**********************************************************

                    print "</td><tr>";

                    print "<tr><td>";
                    print "<td align=\"right\" valign=\"bottom\" width=\"83px\">";
                          print "<form action=\"chat_management.php\" target=\"place\" method=\"post\">";
                            print "<input type=\"hidden\" value=\"".$ActualQvantumPage."\" name=\"ActualQvantumPage\">";
                            print "<input type=\"hidden\" name=\"events\" value=\"show_chat\">";
                            print "<input type=\"hidden\" name=\"roll_show\" value=\"".$roll_show."\">";
                            print "<input type=\"hidden\" name=\"Ch_ID\" value=\"".$sql_array_adm->ID."\">";
                            print "<input type=\"hidden\" name=\"PageNo\" value=\"".$PageNo."\">";
                            print "<input type=\"submit\" value=\"".CH_ZRUS_NAHLAD."\" style=\"width :120px; background-color: ".BUTTON_ON_OUT.";\"
                            onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                            onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\">";
                          print "</form>";
                    print "</td></tr>";

                    print "</table>";
                };
            }
            print "</table>";
            $counter++;
        }


        print "<br />";
        PrintLine();

    //**************************************************************************
    //
    //Vytvorenie menu pre vyber zobrazovanej stranky (rozdelenie zobrazovane hotovaru) - ulozene dole
    //
    //**************************************************************************
    $sql_psel= "SELECT COUNT(*) FROM chat";
    $sql_array_adm = mysql_fetch_row(mysql_query($sql_psel));
    do{
      if (($sql_array_adm[0]/$ItemsOnPage)<=1) break;
       print"<center><table style=\"position:relative;  top:5px;\"><tr>";

// Podmienka prvej >>>> --------------------------------------------------------------------
      if(($sql_array_adm[0]/$ItemsOnPage>$ShowQvantumPage) and ($ActualQvantumPage-$ShowQvantumPage>=0)){
             print "<td>";
             print "<form  action=\"chat_management.php\" target=\"place\" method=\"post\">";
             if($sql_array_adm[0]>$ShowQvantumPage)
               print "<input type=\"submit\" value=\"<<<\"  style=\"width :50px; background-color: ".BUTTON_ON_OUT.";\"
                             onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                             onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />";
               $xxx=$ActualQvantumPage-$ShowQvantumPage;
               $Pagexxx=$xxx;
               print "<input type=\"hidden\" value=\"".$Pagexxx."\" name=\"PageNo\">";
               print "<input type=\"hidden\" value=\"".$xxx."\" name=\"ActualQvantumPage\">";
               print "<input type=\"hidden\" value=\"".$Path."\" name=\"path\">";
               print "<input type=\"hidden\" value=\"".$Category_ID."\" name=\"ID\">";
             print "</form>";
             print "</td>";
             }
 //--------------------------------------------------------------------------------------

//podmienka zvysnych stranok------------------------------------------------------------
          if(($ActualQvantumPage/$ShowQvantumPage)==floor(($sql_array_adm[0]/$ItemsOnPage)/$ShowQvantumPage))
              { if($sql_array_adm[0]%$ItemsOnPage==0)
                    $ShowActualQvantumPage=((($sql_array_adm[0]/$ItemsOnPage)%$ShowQvantumPage));
                else
                    $ShowActualQvantumPage=((($sql_array_adm[0]/$ItemsOnPage)%$ShowQvantumPage)+1);
              }
          else
              {$ShowActualQvantumPage=$ShowQvantumPage;}
 //---------------------------------------------------------------------------------------
      for($i=$ActualQvantumPage;$i<$ActualQvantumPage+$ShowActualQvantumPage;$i++)
    {
      print "<form  action=\"chat_management.php\" target=\"place\" method=\"post\">";
          print "<td>";
          $Xi=$i+1;
          if($PageNo==$i)
            print "<input type=\"submit\" value=\"".$Xi."\" name=\"PageNo\"  style=\"width :50px; background-color: ".BUTTON_ON_OVER.";\" />";
          else
            print "<input type=\"submit\" value=\"".$Xi."\" name=\"PageNo\" style=\"width :25px; background-color: ".BUTTON_ON_OUT.";\"
                            onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
                            onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\"
                        />";
          print "<input type=\"hidden\" value=\"1\" name=\"PageQuanter\" />";
          print "<input type=\"hidden\" value=\"".$ActualQvantumPage."\" name=\"ActualQvantumPage\" />";
          print "<input type=\"hidden\" value=\"".$Path."\" name=\"path\"/>";
          print "<input type=\"hidden\" value=\"".$Category_ID."\" name=\"ID\" />";
          print "</form>";
          print "</td>";
    }

 //podmienka doprednej >>>> -----------------------------------------------------------
if(($sql_array_adm[0]/$ItemsOnPage) > ($ActualQvantumPage+$ShowQvantumPage)){
      print "<td>";
      print "<form  action=\"chat_management.php\" target=\"place\" method=\"post\">";
      print "<input type=\"submit\" value=\">>>\"  style=\"width :50px; background-color: ".BUTTON_ON_OUT.";\"
              onmouseover=\"this.style.backgroundColor='".BUTTON_ON_OVER."'; this.style.fontWeight='bold';\";
              onmouseout=\"this.style.backgroundColor='".BUTTON_ON_OUT."'; this.style.fontWeight='normal';\" />";
      $xxx=$ActualQvantumPage+$ShowQvantumPage;
      $Pagexxx=$xxx;
      print "<input type=\"hidden\" value=\"".$Pagexxx."\" name=\"PageNo\" />";
      print "<input type=\"hidden\" value=\"".$xxx."\" name=\"ActualQvantumPage\" />";
      print "<input type=\"hidden\" value=\"".$Path."\" name=\"path\" />";
      print "<input type=\"hidden\" value=\"".$Category_ID."\" name=\"ID\" />";
    print "</form>";
    print "</td>";
    }
 //--------------------------------------------------------------------------------------
    print "</tr></table></center>";
    PrintLine();
    }while(false);




        mysql_close();
}
while(false)
?>


</body>
</html>
